$regfile = "m16def.dat"
$crystal = 1000000

'Inisialisasi variable Global
Dim Input_pinb As Integer , Icounter As Integer , Itemp As Long
Dim Winput_adc(6) As Word
Dim Wref_adc(6) As Word

'Definisi vektor interupsi
    On Timer0 Fint_handle_timer0

'Declarasi fungsi
Declare Sub Inisialisasi()

'Fungsi Utama
Fmain:
    Call Inisialisasi()
    Lcd "W E L C O M E"
    Waitms 1000
    Do
    Loop
    Portc = &HAA
    End

'Fungsi Interupsi Timer0
Fint_handle_timer0:
   Dim Ichannel As Integer
   'Baca data input ADC
   For Ichannel = 0 To 7
       Winput_adc(ichannel) = Getadc(ichannel)
       If Winput_adc(ichannel) > Wref_adc(ichannel) Then
           Itemp = 1
           Shift Itemp , Left , 1
           Portc = Portc And Itemp
       End If
   Next Ichannel

   Input_pinb = Pinb And 1
   'Input_pinb = 0
   If Pinb.0 = 0 Then
      Portc = &H07
   End If
Return

'Inisialisasi
Sub Inisialisasi()
    Dim A As Byte

    'Inisialisasi LCD
    Config Lcdpin = Pin , Db4 = Portd.4 , Db5 = Portd.5 , Db6 = Portd.6 , Db7 = Portd.7 , E = Portd.2 , Rs = Portd.0
    Config Lcd = 16 * 2
    Initlcd
    Cls

    'Inisialisasi Port
    Config Portc = Output
    Config Portd = Output
    Portb = &HFF

    'Inisialisasi Timer0
    Config Timer0 = Timer , Prescale = 1024

    'Inisialisasi ADC
    Config Adc = Single , Prescaler = Auto
    Start Adc

    'Inisialisasi Interupsi
    Enable Interrupts
    '-Inisialisasi Interupsi Timer0
    Enable Timer0
    Start Timer0

    'Inisialisasi variable awal
    Icounter = 0

End Sub
End